package cn.piesat.scanning.service.impl;

import cn.piesat.scanning.aspect.schedulerTask.SchedulerTaskFileRecord;
import cn.piesat.scanning.dao.DbDmsScanningValidationDAO;
import cn.piesat.scanning.dto.DbDmsScanningValidationDTO;
import cn.piesat.scanning.service.DbDmsScanningValidationService;
import cn.piesat.scanning.service.DbDmsSchedulerTaskFileRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author zyp
 * @date 2021/4/26
 */
@Service("dbDmsScanningValidationService")
public class DbDmsScanningValidationServiceImpl implements DbDmsScanningValidationService {

    @Autowired
    private DbDmsScanningValidationDAO dbDmsScanningValidationDAO;
    @Autowired
    private DbDmsSchedulerTaskFileRecordService dbDmsSchedulerTaskFileRecordService;
    @Override
    public void addEntity(DbDmsScanningValidationDTO dto, String taskId) {
        try {
            dbDmsScanningValidationDAO.save(dto);
            dbDmsSchedulerTaskFileRecordService.dataResults(taskId,dto.getFileName(),true);
        } catch (Exception e){
            dbDmsSchedulerTaskFileRecordService.dataResults(taskId,dto.getFileName(),false);
            e.printStackTrace();
        }
    }

    @Override
    @SchedulerTaskFileRecord("dtos")
    public void addEntityBatch(List<DbDmsScanningValidationDTO> dtos, String taskId) {
        if (CollectionUtils.isEmpty(dtos)) {
            return;
        }
        dbDmsScanningValidationDAO.saveAll(dtos);
    }

    @Override
    public List<DbDmsScanningValidationDTO> findBySatelliteAndDataLevelAndProductIdentifyAndFileDateBetween(String satellite, String level, String mathexp, String startTime, String endTime) {
        return dbDmsScanningValidationDAO.findBySatelliteAndDataLevelAndProductIdentifyAndFileDateBetween(satellite,level,mathexp,startTime,endTime);
    }
}
